package com.huilian.iotbox.admin.controller;

import com.huilian.iotbox.admin.service.DeliveryAddressService;
import com.huilian.iotbox.admin.service.UserService;
import com.huilian.iotbox.data.common.ServerResponse;
import com.huilian.iotbox.data.controller.BaseController;
import com.huilian.iotbox.data.po.DeliveryAddress;
import com.huilian.iotbox.data.vo.UserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * @author 谢洛涛
 * @date 2021/9/7 9:20
 */
@RestController
@RequestMapping("/api/deliveryAddress")
public class DeliveryAddressController extends BaseController {
    @Autowired
    private DeliveryAddressService deliveryAddressServie;
    @Autowired
    private UserService userService;

    @DeleteMapping("/{deliveryAddressId}")
    public ServerResponse delete(HttpServletRequest request, @PathVariable Integer deliveryAddressId){
        UserInfo userInfo = userService.getLoginUserInfo(request);
        return deliveryAddressServie.delete(userInfo.getId(),deliveryAddressId);
    }

    @GetMapping("/findDeliveryAddress/{deliveryAddressId}")
    public ServerResponse findDeliveryAddress(HttpServletRequest request, @PathVariable Integer deliveryAddressId){
        return ServerResponse.createBySuccess(deliveryAddressServie.findDeliveryAddress(deliveryAddressId));
    }
}
